﻿using System.Collections.Generic;
using System.Linq;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现列表的扩展方法
        /// </summary>
        public static class ListExtension
        {
                /// <summary>
                /// 对列表项进行指定条件的智能查询
                /// </summary>
                /// <typeparam name="T">支持智能查询的类型</typeparam>
                /// <param name="list">列表</param>
                /// <param name="conditions">查询条件集合</param>
                /// <returns>查询结果列表</returns>
                public static List<T> Query<T>(this List<T> list, List<QueryCondition<T>> conditions) where T : class
                {
                        return conditions.Aggregate(list, (current, item) => current.AsQueryable().Where(item.GenerateLambdaDelegate()).ToList());

                        //foreach (var item in conditions)
                        //{
                        //        list = list.AsQueryable().Where(item.GenerateLambdaDelegate()).ToList();
                        //}

                        //return list;
                }
        }
}